﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using UNDP_Projects.Data_Access;

using UNDP_Projects.Classes;

namespace UNDP_Projects.CO
{
    public partial class Approved_Project_Reports : PdfCreator
    {
        protected void Page_PreInit(object sender, EventArgs e)
        {
            /*if (User.IsInRole("Project"))
            {
                MasterPageFile = "~/MasterPages/Project.Master";
            }
            if (User.IsInRole("Programme"))
            {
                MasterPageFile = "~/MasterPages/Programme.Master";
            }
            if (User.IsInRole("Administrator"))
            {
                MasterPageFile = "~/MasterPages/CO.Master";
            }
            if (User.IsInRole("Project") && User.IsInRole("Programme"))
            {
                MasterPageFile = "~/MasterPages/ProgProject.Master";
            }*/
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ApprovedProjectsGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "view")
            {
                //Get the selected row
                int currentRowIndex = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = ApprovedProjectsGridView.Rows[currentRowIndex];

                //Get the Datakeynames for the selected row
                string proj = this.ApprovedProjectsGridView.DataKeys[currentRowIndex].Values["project_id"].ToString();
                string yr = this.ApprovedProjectsGridView.DataKeys[currentRowIndex].Values["year_id"].ToString();
                string reprt_per = this.ApprovedProjectsGridView.DataKeys[currentRowIndex].Values["report_period_id"].ToString();

                //ProjectLabel.Text = "Project : " + proj;
                //YearLabel.Text = "Year : " + yr;
                //ReportPeriodLabel.Text = "Report period : " + reprt_per;

                Session["App_Project"] = long.Parse(proj);
                Session["App_ReportPeriod"] = long.Parse(reprt_per);
                Session["App_Year"] = long.Parse(yr);

                Response.Redirect("~/CO/ApprovedProjectReport.aspx");
            }
            else if (e.CommandName == "pdf")
            {
                //Get the selected row
                int currentRowIndex = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = ApprovedProjectsGridView.Rows[currentRowIndex];

                //Get the Datakeynames for the selected row
                string selPROJ = this.ApprovedProjectsGridView.DataKeys[currentRowIndex].Values["project_id"].ToString();
                string selYr = this.ApprovedProjectsGridView.DataKeys[currentRowIndex].Values["year_id"].ToString();
                string selRPRD = this.ApprovedProjectsGridView.DataKeys[currentRowIndex].Values["report_period_id"].ToString();

                long proj = long.Parse(selPROJ);
                long reportp = long.Parse(selRPRD);
                long year = long.Parse(selYr);

                //PdfCreator NewPdfDoc = new PdfCreator();
                //NewPdfDoc
                CreatePDF(proj, reportp, year);
            }
        }
    }
}